<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 409px;
            border-bottom: 2px solid blue;
            border-left: 2px solid blue;
            border-right: 2px solid blue;
        }

        input {
            border: 2px solid blue;
            height: 40px;
            width: 400px;
            border-radius: 5px;
            outline: none;
        }
    </style>
</head>

<body>
    <input type="text">
    <div></div>
    <button>关闭历史</button>
</body>

</html>
<script>

    var input = document.querySelector('input');
    var div = document.querySelector('div')
    var button = document.querySelector('button')

    input.addEventListener('keyup', function (e) {
        input.onfocus = function () {
            div.style.display = 'block'
        }
        if (e.keyCode == 13) {
            var id = input.value
            localStorage.setItem('local', id)
            if (id == '') {
                localStorage.getItem(id)
            }
            //创建p
            var p = document.createElement('p')
            p.innerHTML = input.value
            div.insertBefore(p, div.children[0])
            //   insertBefore()方法是在指定的已有的节点之前插入新的节点，它有两个值，第一个值为要插入的内容，第二个值为指定节点。
        }
    })

    button.onclick = function () {
        div.style.display = 'none'
    }


</script>